package model.qxModel;

import empty.power.Power;
import unit.DbTool;

import java.util.List;

public class PowerModel {
    public int grant(Power power) throws Exception {
        String sql = "INSERT INTO permissions(user_id,file_id,file_qx) VALUES(?,?,?)";
        return DbTool.DML(sql,power.getUser_id(),power.getFile_id(),power.getFile_qx());
    }

    public int back(Power power) throws Exception {
        String sql = "DELETE FROM permissions WHERE id = ?";
        return DbTool.DML(sql,power.getId());
    }

    public List<Object[]> selectAll() throws Exception {
        String sql = "SELECT * FROM permissions";
        return DbTool.DQL(sql);
    }

    public List<Object[]> selectUserID(int user_id) throws Exception {
        String sql = "SELECT * FROM permissions WHERE user_id = ?";
        return DbTool.DQL(sql,user_id);
    }


    public List<Object[]> selectFileID(int file_id) throws Exception {
        String sql = "SELECT * FROM permissions WHERE file_id = ?";
        return DbTool.DQL(sql,file_id);
    }
}
